<template>
  <div class="form">
    <el-form
      :inline="true"
      label-suffix="："
      :label-width="labelWidth"
      :size="size"
      :model="model"
      ref="form"
    >
      <slot></slot>
      <div v-show="hidden">
        <slot name="hidden"> </slot>
      </div>
    </el-form>
    <el-button
      type="primary"
      icon="Search"
      @click="search"
      :size="size"
    >
      搜索
    </el-button>
    <el-button type="info" icon="Refresh" @click="reset" :size="size">
      重置
    </el-button>
    <el-button
      type="primary"
      @click="expend"
      :size="size"
      class="collapse"
    >
    <el-icon style="transform: rotate(90deg)">
                <MoreFilled />
              </el-icon>
      {{ hidden ? "折叠" : "更多条件" }}
    </el-button>
    <slot name="append">

    </slot>
  </div>
</template>

<script>
import { defineComponent } from "vue";
import { Search, Refresh,MoreFilled } from "@element-plus/icons-vue";
export default defineComponent({
  props: {
    size: {
      type: String,
      default: "small",
    },
    // 隐藏 清除筛选条件
    hideClean: {
      type: Boolean,
      default: false,
    },
    // 在清空筛选条件后提交
    submitAfterReset: {
      type: Boolean,
      default: false,
    },
    labelWidth: {
      type: String,
      default: "100px",
    },
    model:{
      type:Object,
      default:()=>{}
    }
  },
  emits:["search","reset"],
  data() {
    return {
      collapse: false,
      hidden: false,
    };
  },
  methods: {
    search() {
      this.$emit("search");
    },
    reset() {
      this.$emit("reset");
      if (this.submitAfterReset) {
        this.$emit("search");
      }
    },
    expend() {
      this.hidden = !this.hidden;
    },
  },
});
</script>

<style lang="scss" scoped>
.form {
  :deep(.el-form-item) {
    margin-right: 0;
    margin-bottom: 0;
    width: 100%;
    .el-form-item__label {
      font-size: 12px;
    }
  }
  :deep(.el-row){
    margin-bottom: 8px;
    padding-right: 16px;
  }
}
.collapse {
  transition: all 0.5s ease;
}
</style>
